import {IComponent} from './Components';

class ComponentDecorator implements IComponent{
  name:string;
  component:IComponent;
  constructor(component:IComponent){
    this.component = component;
    this.name = component.name;
  }
  display():void{
    // 调用原有的业务
    this.component.display();
  }
}

class BlackBorderedDecorator extends ComponentDecorator{
  component:IComponent;
  constructor(component:IComponent){
    super(component);
  }
  display():void{
    // 增加新业务
    this.setBlackBorder();
    // 原有业务
    super.display();
  }
  // 新业务
  private setBlackBorder():void{
    console.log(`组件${this.component.name}添加了黑色边框`);
  }
}

class ScrollBarDecorator extends ComponentDecorator{
  component:IComponent;
  constructor(component:IComponent){
    super(component);
  }
  display():void{
    // 增加新业务
    this.setScrollBar();
    // 原有业务
    super.display();
  }
  // 新业务
  private setScrollBar():void{
    console.log(`组件${this.component.name}增加了滚动条`);
  }
}

export {BlackBorderedDecorator, ScrollBarDecorator}